﻿using OrchardCore.Data.Migration;
using System.Threading.Tasks;
using Ruitu.Edu.TrainingDemo.Indexes;
using YesSql.Sql;

namespace Ruitu.Edu.TrainingDemo.Migrations
{
    public class BookMigrations : DataMigration
    {
        public async Task<int> CreateAsync()
        {
            // 创建 Book 表
            await SchemaBuilder.CreateMapIndexTableAsync<BookIndex>(table => table
                  //.Column<string>(nameof(BookIndex.Title))
                  .Column<string>(nameof(BookIndex.Author))
            );
            return 1; // 返回迁移版本号
        }

        public async Task<int> UpdateFrom1Async()
        {
            await SchemaBuilder.AlterTableAsync(nameof(BookIndex), table => table
            .AddColumn<string>(nameof(BookIndex.Title))
            );

            return 2;
        }
    }
}
